package com.wang.hashtest;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

//使用迭代器（Iterator）EntrySet 的方式进行遍历
public class HashMapTest1 {
    public static void main(String[] args) {
        Map<Integer,String> map = new HashMap<>();

        map.put(1,"java");
        map.put(2,"c++");
        map.put(3,"golang");
        map.put(4,"python");
        map.put(5,"php");

        Iterator<Map.Entry<Integer,String>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry<Integer,String> entry = iterator.next();
            System.out.println(entry.getKey());
            System.out.println(entry.getValue());
        }
    }

}
